$(function() {
	
	// 是否到达底部
	var buttom = false;
	
	// 请求更多的数据
	$(document).on("swipeup",function(){
			var winH =$(window).height();
			var myScroll = $(window).scrollTop();
			if(($(document).height()<= winH||($('body').height() - myScroll) <= winH )&&!buttom){
				console.log("到底了");
				buttom=true;
				var nextPage = $("#nextPage").val();
				var totalPage = $("#totalPage").val();
				if (Number(nextPage) <= Number(totalPage)) {// 如果当前页不是最后一页，则进行请求
					if(Number(totalPage)!=Number("1")){
					$(".slideToMore").hide();
					$(".loading").show();
					getMoreMsg();
					}
				}else{
					$(".slideToMore").hide();
					//如果不是第一页,并且没有数据了，则提示到底了
					if(Number(totalPage)!=Number("1")){
						$(".slideToMore").text("到底了");
						$(".slideToMore").show();
					}
				}
			}
	})

	// 获得更多的数据
	function getMoreMsg() {
		//成功回调函数
		var success = function(result) {
			
			if(result.code == 0 ){
				//获取数据
				var data = result.data;
				//获取到用户的信息
	            var userName = $("#userName").val();
	            var headImage = $("#headImage").val();
	            
	            //需要转换的字段
	            var createTime = "";
	            var commissionStatus = "";
	            
	            //隐藏旋转框
	            $(".slideToMore").show();
				$(".loading").hide();
		
				//进行数据铺展
				for (var i = 0; i < data.length; i++) {		
					//对时间进行格式转换
					var createTime = formatTime(data[i].commission.createTime, 0);
					//对状态进行选择
				    switch (data[i].commission.commissionStatus) {
					case 0:
						commissionStatus = "结算中";
						break;
					case 1:
						commissionStatus = "结算成功";
						break;
					case 2:
						commissionStatus = "结算失败";
						break;
					default:
						break;
					}
				    
					//构建数据
				    var str = '<div class="block commission_info">'
				    	+'<div class="commission_price">'
				    	+'<p class="user_info">'
				    	+'<img src="'+headImage+'" />'
				    	+userName
				    	+'</p>'
				    	+'<span class="status1">+'+data[i].commission.money+'</span>元'
				    	+'</div>'
				    	+'<div class="other_info">'
				    	+'<p class="order_price">订单额：'+data[i].orders.ordersTotalPrice+'元</p>'
				    	+'<p class="status">'+commissionStatus+'</p>'
				    	+'<p class="datetime">'+createTime+'</p>'
				    	+'</div>'
				    	+'</div>';
				    //添加数据
				    $("#content").append(str);				
				}

				//对标志进行修改
				buttom = false;
				// 如果不是最后一页，则对页数进行增加
				var nextPage = $("#nextPage").val();
				var totalPage = $("#totalPage").val();
				if (Number(nextPage) <= Number(totalPage)) {//TODO
					nextPage = Number(nextPage) + Number(1);
					$("#nextPage")[0].value = nextPage;
				}else{
					$(".slideToMore").hide();
				}	
			}else {
				tip.content(result.retMsg).show();
				$(".slideToMore").hide();
				$(".loading").hide();
			}

		}

		//失败回调函数
		var error = function() {
			$(".slideToMore").show();
			$(".loading").hide();	
			alert("请求失败");
			//对标志进行修改
			buttom = false;
		}

		//进行请求
		var nextPage = $("#nextPage").val();
		var url = base_url + "customer/customerfindCommisionByPage";
		var params="pageNum="+nextPage;
		doAjax("POST", url, params, success, error, true, false);
	}
	
})

